package com.wisdomparking.control;

import java.util.Date;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.wisdomparking.config.mvc.Result;
import com.wisdomparking.config.mvc.ResultGenerator;

import lombok.ToString;
import lombok.Value;

@RestController
public class DemoController {
	
	@RequestMapping("index")
	public ModelAndView index() {
		return new ModelAndView("index");
	}
	
	@RequestMapping("demo")
	public Result<User> t() {
		return ResultGenerator.genSuccessResult(new User("xxx", 37, new Date()));
	}
	
	@RequestMapping("demo1")
	public Result<User> t1() {
		return ResultGenerator.genResult(1, new User("xxx", 37, new Date()), "test");
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping("demo2")
	public Result t2() {
		return ResultGenerator.genSuccessResult();
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping("demo3")
	public Result t3() {
		System.out.println(HttpStatus.INTERNAL_SERVER_ERROR);
		return ResultGenerator.genErrorResult("error");
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping("demo4")
	public Result t4() {
//		int a = 5;
//		int b = 5;
//		a = 100 / (a - b);
//		String[] arr = "aaaa,bbbb".split(",");
//		System.out.println(arr[4].substring(1, 2));
		String s = "ssss";
		System.out.println(s.substring(0, 100));
//		User user = null;
//		user.getAge();
		return ResultGenerator.genSuccessResult();
	}
}

@Value
@ToString
class User{
	private String userName;
	private int age;
	private Date birthday;
}
